import request from '@/utils/request'
import type {
  categoryResponseData,
  AttrResponseData,
  Attr,
} from '@/api/product/type'
enum API {
  C1_URL = '/admin/product/getCategory1',
  C2_URL = '/admin/product/getCategory2/',
  C3_URL = '/admin/product/getCategory3/',
  ATTR_URL = '/admin/product/attrInfoList/',
  ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo',
  DELETEATTR_URL = '/admin/product/deleteAttr/',
}

//获取各级分类
export const reqC1 = () => request.get<any, categoryResponseData>(API.C1_URL)

export const reqC2 = (CID: number | string) =>
  request.get<any, categoryResponseData>(API.C2_URL + CID)

export const reqC3 = (CID: number | string) =>
  request.get<any, categoryResponseData>(API.C3_URL + CID)

//获取商品各级的属性名称
export const reqAttr = (
  C1ID: number | string,
  C2ID: number | string,
  C3ID: number | string,
) =>
  request.get<any, AttrResponseData>(API.ATTR_URL + `${C1ID}/${C2ID}/${C3ID}`)

//添加或更改属性具体属性值
export const reqAddOrUpadateAttr = (data: Attr) =>
  request.post<any, any>(API.ADDORUPDATEATTR_URL, data)

export const reqDeleteAttr = (attrId: number) =>
  request.delete<any, any>(API.DELETEATTR_URL + attrId)
